document.write('<link rel="stylesheet" href="../css/register.css">');

$(function (){
    $('#password').on('blur',function (){
        if(this.value.length===0){
            $('#passwordTips').attr("class","invalid").text("输入不可为空");
        }else{
            $('#passwordTips').attr("class","available").text("格式正确");
        }
    });
    $('#repeatedPassword').on('blur',function (){
        if(this.value!==document.getElementById("password").value){
            $('#repeatedPasswordTips').attr("class","invalid").text("密码输入不一致");
        }else{
            $('#repeatedPasswordTips').text("");
        }
    });
    $('#putEdit').on('click',function (e) {
        e.preventDefault();
        var url
        if(!document.getElementById("listOption").checked&&!document.getElementById("bannerOption").checked){
            console.log("两个都未选中");
            url='/account/editAccount?listOption=false&bannerOption=false';
        }else if(document.getElementById("listOption").checked&&!document.getElementById("bannerOption").checked){
            console.log("第二个未选中");
            url='/account/editAccount?bannerOption=false';
        }else if(!document.getElementById("listOption").checked&&document.getElementById("bannerOption").checked){
            console.log("第1个未选中");
            url='/account/editAccount?listOption=false';
        }else{
            console.log("两个都选中");
            url='/account/editAccount';
        }
        let datas = $('#editAccount').serialize();
        if(document.getElementById("password").value!==null&&document.getElementById("password").value.length!==0&&
            document.getElementById("password").value===document.getElementById("repeatedPassword").value){
            console.log("格式");
            $.post(url,datas,function (data) {
                if(data.code===2){
                    console.log("456");
                    location.href="/account/signonForm";
                }
            });
        }else{
            window.alert("请按照正确格式填写信息");
        }
    });
});